cmake_minimum_required(VERSION 3.2)
project(ffmpeg_transcoder)

if (APPLE)
    option(USE_BMCODEC "Use bitmain hardware codec" OFF)
    option(USE_OUTPUT_FILE "Output as h264 file" ON)
    option(USE_FFMPEG_STATIC "Use ffmpeg static library" OFF)
else ()
    option(USE_BMCODEC "Use bitmain hardware codec" ON)
    option(USE_OUTPUT_FILE "Output as h264 file" OFF)
    option(USE_FFMPEG_STATIC "Use ffmpeg static library" ON)
endif ()

if (USE_OUTPUT_FILE)
    add_definitions(-DUSE_OUTPUT_FILE=1)
endif()

set(CMAKE_CXX_STANDARD 14)

set(TOP ${CMAKE_CURRENT_SOURCE_DIR})
if (USE_BMCODEC)
    if (USE_FFMPEG_STATIC)
       set(FFMPEG_ROOT ${TOP}/../bm_ffmpeg_static_sdk)
    else(USE_FFMPEG_STATIC)
        set(FFMPEG_ROOT ${TOP}/../bm_ffmpeg_sdk)
    endif()
    add_definitions(-DUSE_BMCODEC=1)
else()
    if (APPLE)
        set(FFMPEG_ROOT /usr/local)
    else()
        set(FFMPEG_ROOT $ENV{HOME}/third_party)
    endif()
endif()

set(ffmpeg_inc_dirs ${FFMPEG_ROOT}/include)
set(ffmpeg_link_dirs ${FFMPEG_ROOT}/lib)

if (USE_FFMPEG_STATIC)
set(ffmpeg_link_libs 
    avfilter avformat avcodec avutil swresample swscale 
    bmjpulite bmjpuapi bmvpulite bmvpuapi bmvideo bmvppapi bmpciebuffer 
    osip ssl crypto pthread freetype dl m z)
else()
    set(ffmpeg_link_libs avfilter avformat avcodec avutil swresample swscale pthread)
endif()

include_directories(${ffmpeg_inc_dirs})
link_directories(${ffmpeg_link_dirs})

add_executable(fftrans
        ffmpeg_transcode.cpp
        main.cpp)
target_link_libraries(fftrans ${ffmpeg_link_libs})
